package com.example.demo.controller.system;

import com.example.demo.annoation.Log;
import com.example.demo.bean.AjaxRes;
import com.example.demo.bean.sysfile.SysFileCateDO;
import com.example.demo.controller.BaseAdminController;
import com.example.demo.enums.BusinessType;
import com.example.demo.service.ISysFileCateService;
import com.example.demo.dto.sysfile.SysFileCatePageReqVO;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

@RequestMapping(value = "/system/sys_file_cate")
@RestController
public class SysFileCateController extends BaseAdminController {

    @Resource
    private ISysFileCateService sysFileCateService;

    @GetMapping("/list")
    public AjaxRes list(SysFileCatePageReqVO sysFileCatePageReqVO) {
        return AjaxRes.success(sysFileCateService.list(sysFileCatePageReqVO));
    }

    @PostMapping("/insert")
    @Log(title = "新增文件分类", businessType = BusinessType.INSERT)
    public AjaxRes insert(@RequestBody SysFileCateDO sysFileCateDO) {
        return toAjax(sysFileCateService.addSysFileCate(sysFileCateDO));
    }

    @DeleteMapping("/delete/{sysFileCateId}")
    @Log(title = "删除文件分类", businessType = BusinessType.DELETE)
    public AjaxRes delete(@PathVariable("sysFileCateId") Long sysFileCateId) {
        return toAjax(sysFileCateService.deleteSysFileCate(new SysFileCateDO().setId(sysFileCateId)));
    }

    @PutMapping("/update")
    @Log(title = "修改文件分类", businessType = BusinessType.UPDATE)
    public AjaxRes update(@RequestBody SysFileCateDO sysFileCateDO) {
        return toAjax(sysFileCateService.updateSysFileCate(sysFileCateDO));
    }

    @GetMapping("/{sysFileCateId}")
    public AjaxRes query(@PathVariable("sysFileCateId") Long sysFileCateId) {
        return AjaxRes.success(sysFileCateService.getSysFileCate(new SysFileCateDO().setId(sysFileCateId)));
    }
}
